#ifndef _RENDER_H_
#define _RENDER_H_

#include "singleton.h"
#include "xml.h"
#include "color.h"
#include "matrix.h"
#include "file.h"
#include "texture.h"
#include "effect.h"
#include "ivbuffer.h"
#include <windows.h>

enum device_state
{
	device_ok,
	device_lost,
	device_error
};

enum buffer_type
{
	buffer_color   = 1l,
	buffer_z	   = 2l,
	buffer_stensil = 4l
};

enum primitiv_type
{
	pr_points			= 1,
	pr_lines			= 2,
	pr_line_strip		= 3,
	pr_triangles		= 4,
	pr_triangle_strip	= 5
};

enum cull_mode
{
	cullmode_none	= 1,
	cullmode_cw		= 2,
	cullmode_ccw	= 3
};

enum fill_mode
{
	fillmode_points		= 1,
	fillmode_wireframe	= 2,
	fillmode_solid		= 3
};

enum light_type
{
	light_point = 1,
	light_spot = 2,
	light_directional = 3,
	light_none = 0
};

struct material
{
	color diffuse;
	color ambient;
	color specular;
	color emission;
	float shininess;
};

struct light
{
	light_type type;
	color diffuse;
	color specular;
	color ambient;
	vector3 position;
	vector3 direction;
};

class render
{
public:
	virtual ~render(){}

	virtual void init(xml_node& _node)=0;
	virtual void reset()=0;
	virtual void free()=0;
	virtual device_state get_state()=0;

	virtual void begin()=0;
	virtual void end()=0;
	virtual void clear(u32 _type,color _color,float _z,u32 _stencil)=0;

	virtual vbuffer* create_vbuffer(buffer_usage _usage,u32 _vformat,u32 _blocksize,u32 _lenth)=0;
	virtual ibuffer* create_ibuffer(buffer_usage _usage,u32 _size)=0;
	virtual void	 set_vbuffer(vbuffer* _vbuffer)=0;
	virtual void	 set_ibuffer(ibuffer* _ibuffer)=0;
	virtual void	 draw_vbuffer(primitiv_type _prtype,u32 _start_vrt,u32 _pr_count)=0;
	virtual void	 draw_ibuffer(primitiv_type _prtype,u32 _num_vtx,u32 _start_idx,u32 _pr_count)=0;
	virtual texture* create_texture(const char* _fname)=0;
	virtual void	 set_texture(u32 _stage,texture* _texture)=0;
	virtual effect*  create_effect(file* _file,const char* _vfunc,const char* _pfunc)=0;
	virtual effect*  create_effect(const char* _fname,const char* _vfunc,const char* _pfunc)=0;
	virtual void	 set_effect(effect* _effect)=0;

	virtual void enable_light(bool _enabled)=0;
	virtual void set_light(u32 _stage,light _light)=0;
	virtual void set_material(material _material)=0;
	virtual void set_ambient(color _color)=0;
	virtual void set_cullmode(cull_mode _mode)=0;
	virtual void set_fillmode(fill_mode _mode)=0;

	virtual void set_projection(matrix4 _matrix)=0;
	virtual void set_view(matrix4 _matrix)=0;
	virtual void set_world(matrix4 _matrix)=0;
	virtual void set_viewport(u32 _x,u32 _y,u32 _width,u32 _height)=0;

protected:

	u32  m_width;
	u32  m_height;
	u32  m_bpp;
	bool m_windowed;
};

#endif